<?php
namespace Admin\Controller;
/**
* 文章管理界面
*/
class ArticleController extends CommonController{
	
	public function index(){
	
		$this->display();
	}
	
	public function get_art_list(){
		
		//$m = D('AjArtic','Serivce');
		$n = D('AjArtic');
		$type = I('type');
		$keyword = I('keyword');
		$p = I('p')?I('p'):1;
		$row = I('row')?I("row"):10;
		if($type){
			$map['artsort_id'] = $type;
		}
		if($keyword){
			$map['title'] = array('like','%'.$keyword.'%');
		}
		$arr = array(

					3=>'最新动态',
					5=>'影响力',
					6=>'风采'
					
				);
		$data['data'] = $n->where($map)->limit(($p-1)*$row,$row)->order('id asc')->select();
		foreach($data['data'] as $k=>$v){
			$data['data'][$k]['dateline'] = date("Y-m-d H:i:s",$v['dateline']);
			$data['data'][$k]['type'] = $arr[$v['artsort_id']]?$arr[$v['artsort_id']]:""; 
		}
		$count = $n->where($map)->count();
		$data['page']['total'] = $count;
		$data['page']['cur'] = $p;
		$data['page']['row'] = $row;
		_apiReturn(1, L('success'), $data, $url);
	}
	
	public function change_state(){
		$id = I('id');
		if(!$id)_apiReturn(0, 'miss param id', $data, $url);
		$m = D('AjArtic');
		$map['id'] = $id;
		$temp = $m->where($map)->getField('state');
		if($temp == 1){
			$a = 0;
		}else{
			$a = 1;
		}
		$data['state'] = $a;
		if($m->where($map)->save($data)){
			_apiReturn(1, L('success'), $result, $url);
		}else{
			_apiReturn(0, '数据库保存失败', $data, $url);
		}
	}
	
	 public function artic_del(){
        $this->_del(M('AjArtic'),$_REQUEST['ids']);
    }
	 
	public function artic_more_del(){
        //批量删除
        $m = M('AjArtic');
		$id = array_unique((array)I('ids',0));
		if ( empty($id) ) {
			$this->error('请选择要操作的数据!');
		}
		$map = array('id' => array('in', $id));
		//$mapp = array('uid' => array('in', $id));
		//$mapp['group'] = 'admin';
		if($m->where($map)->delete()){
			//M('AuthGroupAccess')->where($mapp)->delete();
			_apiReturn(1, "删除成功");
		} else {
			_apiReturn(0, "删除失败");
		}
	
    }
	 
	 
	 /**
    * 编辑文章界面
    */
    public function edit(){
    	
    	if($_GET['id']){
    		$this->info = D('AjArtic')->find($_GET['id']);
    	}
        $this->display();
    }
	/**
    * 编辑文章
    */
    public function artic_edit_post(){
        if(IS_POST){
        	
            //$_POST['lasttime'] = Date('Y-m-d H:i:s'); //更新时间
            $m = M('AjArtic');
			$tmpData = $m->create($_POST);
			$tmpData['lasttime'] = Date('Y-m-d H:i:s');
            if($tmpData['id']){
                if($m->save($tmpData)){
                    $this->success('success');
                }else{
                    $this->error('error');
                }
            }else{
				$tmpData['dateline'] = strtotime($tmpData['lasttime']);
                if($m->add($tmpData)){
                    $this->success('success');
                }else{
                    $this->error('error');
                }
            }
        }
    }
	 
	
}
?>